{template 'tpl_header'}
<div class="weui-cells weui-cells_form" style="margin-top: 0;">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label3">手机</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" name="mobile" placeholder="请输入手机号码" disabled
                   value="{$member['mobile']}">
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label3">验证码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" name="authcode" placeholder="请输入验证码"/>
        </div>
        <div class="weui-cell__ft">
            <button type="button" class="weui-vcode-btn">获取验证码</button>
        </div>
    </div>
</div>
<div class='insurance_btn_row'>
    <a href="javascript:;" id="register" class="weui-btn weui-btn_primary">立即重置</a>
</div>
{template 'tpl_footer'}
<script>
    var is_authcode_look = false;
    var is_submit_look = false;
    $(function () {
        $('#register').click(function () {
            //防止重复提交
            if (!is_submit_look) {
                is_submit_look = true;
                var mobile = $('input[name="mobile"]').val();
                var authcode = $('input[name="authcode"]').val();
                if (mobile == '') {
                    is_submit_look = false;
                    $.toast('请填写手机号码', "cancel");
                    return false;
                }
                if (authcode == '') {
                    is_submit_look = false;
                    $.toast('请填写验证码', "cancel");
                    return false;
                }

                var myreg = /^[1][3-8][0-9]{9}$/;
                if (!myreg.test(mobile)) {
                    is_submit_look = false;
                    $.toast('请填写有效的手机号码', "cancel");
                    return false;
                }
                var data = {
                    'action': 'mobile_verification',
                    'authcode': authcode
                };
                $.ajax({
                    url: "{php echo $this->createMobileUrl('ajax')}",
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 1) {
                            var url = "{php echo url('entry', array('m' => 'vj_bontrip','do' => 'me','op' => 'mobile_edit2'),true); }";
                            window.location.replace(url);

                        } else {
                            is_submit_look = false;
                            $.toast(res.msg, "cancel");
                        }

                    },
                    error: function (res) {
                        $.toast('请求失败，请检测网络或联系客服', "cancel");
                    }
                });
            }
        });

        $('.weui-vcode-btn').click(function () {
            if (!is_authcode_look) {
                is_authcode_look = true;
                var mobile = $('input[name="mobile"]').val();
                if (mobile == '') {
                    is_authcode_look = false;
                    $.toast('请填写手机号码', "cancel");
                    return false;
                }
                var myreg = /^[1][3-8][0-9]{9}$/;
                if (!myreg.test(mobile)) {
                    is_authcode_look = false;
                    $.toast('请填写有效的手机号码', "cancel");
                    return false;
                }
                var ajaxurl = "{php echo url('entry', array('m' => 'vj_bontrip','do' => 'sms'),true)}";
                $.ajax({
                    url: ajaxurl,
                    type: "post",
                    dataType: "json",
                    data: {
                        "mobile": mobile,
                        "code_type": '2'
                    },
                    success: function (res) {
                        console.log(res);
                        if (res['ret'] == 0) {
                            $.toast('发送成功');
                            verification();
                        } else {
                            is_authcode_look = false;
                            $.toast(res['msg'], "cancel");
                        }
                    },
                    error: function (r) {
                        console.log(r);
                    }
                });
            }
        });
    });

    function verification() {
        var time = 60;
        var mytime = setInterval(function () {
            var str = "获取验证码";
            var time1 = '重新获取' + time + '秒';
            $('.weui-vcode-btn').text(time1);
            time--;
            if (time < 0) {
                $('.weui-vcode-btn').text(str);
                is_authcode_look = false;
                clearInterval(mytime);
            }
        }, 1000);
    }
</script>